﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

namespace UnitySheet
{
    public class DragSheet : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
    {
        public Sheet sheet;
        Vector3 offset;
        public void OnBeginDrag(PointerEventData eventData)
        {
            offset = sheet.transform.position - Input.mousePosition;
        }

        public void OnDrag(PointerEventData eventData)
        {
            sheet.transform.position = Input.mousePosition + offset;
        }

        public void OnEndDrag(PointerEventData eventData)
        {
            offset = Vector3.zero;
        }

        private void Update()
        {
            if (sheet.yNum > 0)
            {
                transform.position = sheet.anchors[0][0].transform.position;
            }
        }
    }
}
